﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HF.BaseWebCtrlLib;
using HF.Framework.SqlDataContract;
using HF.Framework.DataClientDBAgent;
using HF.WorkFlow.Engine;
using HF.WorkFlow.DataContract;
public partial class BaseUserControls_DyAssignNext : BaseUserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load();
    }
    public override void InitUserControl()
    {
        base.InitUserControl();
        DataTable tmpDt = WorkTaskInstance.GetInstance().GetTaskInsNextOper(WorkflowId, WorktaskId, WorkflowInsId, WorktaskInsId);
        if (tmpDt != null & tmpDt.Rows.Count > 0)
        {
            int n = tmpDt.Rows.Count;
            if (n == 1)
            {
                txtUsers.Text = tmpDt.Rows[0]["userid"].ToString();
            }
            else
            {
                for (int i=0; i < n - 1; i++)
                {
                    txtUsers.Text = txtUsers.Text + tmpDt.Rows[i]["userid"].ToString() + ",";
                }
                txtUsers.Text = txtUsers.Text + tmpDt.Rows[n-1]["userid"].ToString() ;
            }
        }
         
         
    }
    public override void SaveUserControl(bool IsDraft)
    {
        base.SaveUserControl(IsDraft);
        string[] users = txtUsers.Text.Split(',');
        WorkTaskInstanceNextOper nextOper = new WorkTaskInstanceNextOper();
        nextOper.DeleteByTaskInstance(WorktaskInsId);
        foreach (string user in users)
        {
            WorkTaskInstanceNextOperEntity entity = new WorkTaskInstanceNextOperEntity();
            entity.NextOperId = Guid.NewGuid().ToString();
            entity.UserId = user.Trim();
            entity.UserName = "";
            entity.WorkFlowId = WorkflowId;
            entity.WorkTaskId = WorktaskId;
            entity.WorkFlowInstanceId = WorkflowInsId;
            entity.WorkTaskInstanceId = WorktaskInsId;
            entity.Status = "0";
            nextOper.Insert(entity);
        }
    }
}
